import { type ComponentPropertiesResponse, EAlbum01Source, ECourse01Source, EInformation01Source, EIntroduction01MediaType, ENavigation01IconType, ENavigation01Style, EQuestionAnswer01Source, ETeacher01Source, EWebDesignerComponentBackground } from '@/api/designer/model'
import { followThemeValue } from '@/utils/constants'
import { withPublicPath } from '@/utils/publicPath'
import { buildShortUUID } from '@/utils/uuid'
import { type ComponentCode, JumpType } from '../type'

export function withDefaultProperty<
  Code extends ComponentCode,
  ComponentConfig = ComponentPropertiesResponse[Code],
>(code: Code, _property: ComponentConfig): ComponentConfig {
  if (code === 'title01') {
    const property = _property as ComponentPropertiesResponse['title01']
    property.title = '关于我们'
    property.subTitle = 'ABOUT US'
  }
  else if (code === 'carousel01') {
    const property = _property as ComponentPropertiesResponse['carousel01']
    property.items?.push({
      picture: withPublicPath('/images/render-def/carousel01/carousel01.png'),
      description: '',
      jumpValue: '',
      title: '',
      // @ts-ignore
      jumpType: JumpType.None,
      // sort 默认和索引同步
      sort: 0,
      jumpTitle: '',
      jumpUrl: '',
    })
  }
  else if (code === 'navigation01') {
    const property = _property as ComponentPropertiesResponse['navigation01']
    property.style = ENavigation01Style.四个
    property.iconType = ENavigation01IconType.矢量图标
    const presets = [
      {
        icon: 'icon-zixun',
        title: '学习规划',
      },
      {
        icon: 'icon-guihua',
        title: '免费资料',
      },
      {
        icon: 'icon-tuandui',
        title: '进交流群',
      },
      {
        icon: 'icon-tianxie',
        title: '考试测评',
      },
    ]
    property.items?.push(
      ...presets.map(({ icon, title }) => ({
        icon,
        iconRules: {
          min: 2,
          required: true,
        },
        jumpType: JumpType.None as any,
        title,
        titleRules: {
          min: 2,
          required: true,
        },
        id: buildShortUUID(),
        jumpTitle: '',
        jumpUrl: '',
        jumpValue: '',
        iconUseThemeColor: true,
      })),
    )
  }
  else if (code === 'introduction01') {
    const property = _property as ComponentPropertiesResponse['introduction01']
    property.mediaType = EIntroduction01MediaType.图片
    property.items?.push({
      id: buildShortUUID(),
      url: withPublicPath(
        '/images/render-def/introduction01/introduction01.png',
      ),
      coverOrName: '',
    })
    property.title = '新东方培训中心'
    property.description
      = '新东方成立于1993年11月16日，是一家综合性教育科技集团，2006年在美国上市。提供双语、美术、机器人、创客、书法、口才、研学游学等素质素养教育服务，提供留学咨询、出国考试、大学考试、成人英语、家庭教育、高中复读、初中复读、艺考文化课等课程与服务。新东方学校深耕教育20余年，校区遍布全国各地，专注为各年龄段学生提供学习与成长'
  }
  else if (code === 'statistics01') {
    const property = _property as ComponentPropertiesResponse['statistics01']
    const presets = [
      {
        value: '30+',
        title: '年行业经验',
      },
      {
        value: '500+',
        title: '全职教职工',
      },
      {
        value: '2万+',
        title: '每年招生体量',
      },
      {
        value: '100+',
        title: '合作院校',
      },
    ]
    property.items?.push(
      ...presets.map(({ title, value }) => ({
        id: buildShortUUID(),
        title,
        value,
        valueRules: {
          min: 2,
          required: true,
        },
        titleRules: {
          min: 2,
          max: 6,
          required: true,
        },
      })),
    )
    property.background = EWebDesignerComponentBackground.主题色
    property.backgroundValue = followThemeValue.deep.toString()
  }
  else if (code === 'course01') {
    const property = _property as ComponentPropertiesResponse['course01']
    property.source = ECourse01Source.按分类读取
    property.isDisplayDescription = false
    property.isDisplayRecommend = true
  }
  else if (code === 'teacher01') {
    const property = _property as ComponentPropertiesResponse['teacher01']
    property.source = ETeacher01Source.按顺序读取
    property.buttonText = '查看更多'
    property.background = EWebDesignerComponentBackground.主题色
    property.backgroundValue = followThemeValue.light.toString()
  }
  else if (code === 'advantage01') {
    const property = _property as ComponentPropertiesResponse['advantage01']
    const presets = [
      {
        icon: 'icon-zixun',
        title: '系统的测评分析',
        description:
          '我们拥有专业的教育咨询师和学习分析测评系统，科学诊断学生问题成因',
      },
      {
        icon: 'icon-tuandui',
        title: '科学的辅导理念',
        description:
          '培养学生乐学、勤学、善学，以及学生内在学习能力的提升来推动学习成绩的进步',
      },
      {
        icon: 'icon-zixun',
        title: '严格的教学管理',
        description:
          '我们拥有专业的教育咨询师和学习分析测评系统，科学诊断学生问题成因',
      },
      {
        icon: 'icon-tuandui',
        title: '完善的协议保障',
        description:
          '26年正规且具有办学许可的培训学校，全程个性化辅导，1V1专业辅导签署服务协议',
      },
    ]
    property.items?.push(
      ...presets.map(({ description, icon, title }) => ({
        id: buildShortUUID(),
        title,
        titleRules: {
          min: 2,
          max: 16,
          required: true,
        },
        icon,
        iconRules: {
          min: 2,
          required: true,
        },
        description,
        descriptionRules: {
          min: 2,
          required: true,
        },
        iconUseThemeColor: true,
      })),
    )
  }
  else if (code === 'flow01') {
    const property = _property as ComponentPropertiesResponse['flow01']
    const presets = [
      {
        step: '01',
        title: '新生入门指导',
        description:
          '我们拥有专业的教育咨询师和学习分析测评系统，科学诊断学生问题成因。',
      },
      {
        step: '02',
        title: '老师跟进记录',
        description:
          '建立交流群，老师会随时关注学生动态，并及时发现问题﹐解决问题。',
      },
      {
        step: '03',
        title: '打造学习计划',
        description:
          '根据学生所在地及文化专业的情况，给出不同院校的建议，帮助学生辅导心理，增强自信。',
      },
    ]
    property.items?.push(
      ...presets.map(({ description, step, title }) => ({
        id: buildShortUUID(),
        descriptionRules: {
          min: 2,
          required: true,
        },
        step,
        stepRules: {
          min: 1,
          required: true,
        },
        title,
        titleRules: {
          min: 2,
          required: true,
        },
        description,
      })),
    )
  }
  else if (code === 'button01') {
    const property = _property as ComponentPropertiesResponse['button01']
    const presets = [
      {
        text: '在线咨询',
        color: 'linear-gradient(90deg, #FE8207 0%, #F40 100%)',
      },
      {
        text: '400-600-3310',
        color: 'linear-gradient(92deg, #909090 6.82%, #7A7A7A 98.05%)',
      },
    ]
    property.items?.push(
      ...presets.map(({ color, text }) => ({
        id: buildShortUUID(),
        text,
        color,
        textRules: {
          min: 2,
          required: true,
        },
        colorRules: {
          min: 4,
          required: true,
        },
        radius: 24,
        jumpType: JumpType.None as any,
        radiusPc: 68,
      })),
    )
  }
  else if (code === 'album01') {
    const property = _property as ComponentPropertiesResponse['album01']
    property.source = EAlbum01Source.按顺序读取
    property.isShowTitle = true
    property.isShowSubTitle = true
    property.buttonText = '查看更多'
  }
  else if (code === 'video01') {
    const property = _property as ComponentPropertiesResponse['video01']
    property.cover = withPublicPath('/images/render-def/video01/video01.jpg')
    property.background = EWebDesignerComponentBackground.主题色
    property.backgroundValue = followThemeValue.light.toString()
  }
  else if (code === 'questionAnswer01') {
    const property = _property as ComponentPropertiesResponse['questionAnswer01']
    property.source = EQuestionAnswer01Source.按顺序读取
    property.buttonText = '更多问答'
    property.background = EWebDesignerComponentBackground.主题色
    property.backgroundValue = followThemeValue.deep.toString()
  }
  else if (code === 'information01') {
    const property = _property as ComponentPropertiesResponse['information01']
    property.source = EInformation01Source.按顺序读取
    property.buttonText = '查看更多'
    property.background = EWebDesignerComponentBackground.主题色
    property.backgroundValue = followThemeValue.light.toString()
  }
  else if (code === 'consultation01') {
    const property = _property as ComponentPropertiesResponse['consultation01']
    property.avatar = withPublicPath(
      '/images/render-def/consultation01/consultation01.png',
    )
    property.nickName = '赵先生'
    property.course = '广州新东方托福春季封闭集训 / 托福107分'
    property.guide
      = '老师从MIC八大能力模型分析，制定了专属我的学习方案，太棒了！'
    property.buttonText = '咨询适合我的班型'
  }
  else if (code === 'guide01') {
    const property = _property as ComponentPropertiesResponse['guide01']
    property.title = '梦想 启航'
    property.description = '享受高品质教学，有更美妙的方法'
    property.buttonText = '查看课程'
    property.background = EWebDesignerComponentBackground.图片
    property.backgroundValue = withPublicPath(
      '/images/render-def/guide01/guide01.jpeg',
    )
  }
  else if (code === 'feedback01') {
    const property = _property as ComponentPropertiesResponse['feedback01']
    property.title = '定制专属精品课程'
    property.description = '已有 8888+ 学生咨询并领取课程方案'
    property.buttonText = '立即定制'
    property.userName = '请输入您的姓名'
    property.mobile = '请输入您的手机号'
    property.area = '请输入学习城市+区域'
    property.course = '请输入或选择您的意向课程'
    property.remark = '请输入想说的话'
  }
  else if (code === 'attention01') {
    const property = _property as ComponentPropertiesResponse['attention01']
    property.text = '关注公众号 了解更多'
    property.qrCode = withPublicPath(
      '/images/render-def/attention01/attention01.png',
    )
  }
  else if (code === 'honor01') {
    const property = _property as ComponentPropertiesResponse['honor01']

    property.items = [
      {
        picture: withPublicPath(
          '/images/render-def/honor01/honor01.png',
        ),
        title: '2023年度行业标杆教育集团',
        description: '网易新闻金翼奖',
      },
    ] as any
  }
  else if (code === 'evaluation01') {
    const property = _property as ComponentPropertiesResponse['evaluation01']

    property.items = [
      {
        avatar: withPublicPath(
          '/images/render-def/consultation01/consultation01.png',
        ),
        evaluation: '老师层层递进的把企业发展的四大阶段,绩效管理的九大障碍以及绩效管理的六大步骤和四大方法体系中的滚动图和平衡轮由浅入深剖析，愿我们都能学以致用！再次感谢胡老师，也期待明后两天老师更加精彩的授课！感谢公司给我们提供学习的机会，提升自我！',
        userName: '张先生',
        course: '广州新东方SAT强化辅导课程',
      },
    ] as any
  }
  return _property
}
